﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL.ACChar;
using ZF.BLL.Page;
using ZF.BLL;
using GCELibrary.Current;

namespace ZF.WS.Admin.service
{
    public partial class CService :PageBase
    {
        [PageArgument(Key = "type",DefaultValue=null)]
        public string Type { get; set; }
        public string guid { get; set; }
        public bool IsService
        {
            get
            {
                return CMember != null && CMember is ManageMember;
            }
        }
        public IMember CMember { get { return SiteInfo.GetCurrentMember(); } }
        [PageArgument(Key = "ia",DefaultValue=0)]
        public int IsAdmin { get; set; }


        protected void Page_Load(object sender, EventArgs e)
        {
            var member = CMember;
            if (member != null)
            {
                guid = member.MemberId.ToString();
                (new AdminChar()).RegOnLine(member.MemberId, IsService);
            }
            else
            {

                if (IsAdmin == 1)
                {
                    var from = Server.UrlEncode(Request.Url.ToString());
                    this.WarnFactory.CreateWarn(new PageWarnParameter()
                    {
                        DoPage = string.Format("{0}?from={1}", string.Format("{0}/login.aspx", AppKey.SiteKey.ManageDirectory), from),
                        Icon = WarnIcon.Error,
                        JscriptMode = true,
                        AlertPage = "",
                        Link = WarnLink.GoLogin,
                        WarnCode = (int)WarnCode.LoginTimeOut
                    }).Alert();
                    return;
                }
                var oguid = HttpSession.GetSession("service_char_guid");
                if (oguid != null)
                {
                    guid = string.Concat(oguid);
                }
                else
                {
                    guid = Guid.NewGuid().ToString();
                    HttpSession.SetSession("service_char_guid", guid);
                }
                if(this.Type==null)
                    (new AdminChar()).RegOnLine(guid,false);
                else
                    (new AdminChar()).RegOnLine(guid, this.Type);
            }

 
        }
    }
}
